<?php
namespace Models\Model;
use Zend\Db\ResultSet\ResultSet;
use Zend\Db\TableGateway\TableGateway;
use Zend\Db\Sql;
use Zend\Db\Sql\Where;
use Zend\Db\Sql\Select;
use Zend\Paginator\Adapter\DbSelect;
use Zend\Paginator\Paginator;
use Zend\Db\Sql\Predicate;
use Zend\Db\Sql\Expression;
class UserdetailsTable
{
    protected $tableGateway;
	protected $select;
    public function __construct(TableGateway $tableGateway)
    {
        $this->tableGateway = $tableGateway;
		$this->select = new Select();
    }
	public function saveUserDetails($users,$userId)
    {
		$data = array(		
			'user_id'          	=> 	$userId,  		
			//'city'          	=> 	$users['city'],		
			//'state'	        => 	$users['state'],	  	
			//'country'         => 	$users['country'],	  	  
			'address' 	       	=> 	$users['inputAddress'],	
			'pincode' 	       	=> 	$users['pincode'],			
			'phone'	      	 	=> 	$users['inputTelephone'],	  	
			'alterphone'	    => 	$users['alterphone'],	  	
			'landmark'	  		=>  $users['landmark'],
			//'fax'				=>	$users['fax'],	  	
			'location'			=>	$users['location'],	  	
			'status'			=>	1,
			'date_added'		=>	date('Y-m-d H:i:s'), 
			'date_updated'		=>	date('Y-m-d H:i:s'), 	
		);	
		$insertresult=$this->tableGateway->insert($data);	
		return $this->tableGateway->lastInsertValue;		
    }
	public function saveshopDetails($shop,$shopId)
    {
		$data = array(		
			'user_id'          	=> 	$shopId,  		
			'address' 	       	=> 	$shop['inputAddress'],	
			'pincode' 	       	=> 	$shop['pincode'],			
			'phone'	      	 	=> 	$shop['inputTelephone'],	  	  	
			'alterphone'	    => 	$shop['alterphone'],	  	  	
			'location'			=>	$shop['location'],	  	
			'status'			=>	0,
			'date_added'		=>	date('Y-m-d H:i:s'), 
			'date_updated'		=>	date('Y-m-d H:i:s'), 	
		);	
		$insertresult=$this->tableGateway->insert($data);	
		return $this->tableGateway->lastInsertValue;		
    }
	public function updateUserDetails($users,$userId)
    {
		$data = array(		 		
			'user_id'          	=> 	$userId,  		
			//'city'          	=> 	$users['city'],		
			//'state'	        => 	$users['state'],	  	
			//'country'         => 	$users['country'],
           // 'landmark'        => $users['inputLm'],			
			'address' 	       	=> 	$users['address'],	
			'pincode' 	       	=> 	$users['pincode'],			
			'phone'	      	 	=> 	$users['phone'],
            'alterphone'	   	=> 	$users['alterphone'],			
			//'fax'				=>	$users['fax'],	  	
			'location'			=>	$users['location'],	  	
			'status'			=>	1,
			'date_added'		=>	date('Y-m-d H:i:s'), 
			'date_updated'		=>	date('Y-m-d H:i:s'),  	
		);	
		
		$updateorderid=$this->tableGateway->update($data, array('user_id' => $userId));
		return $updateorderid;
    }
	public function updateorderDetailes($order,$orderID)
    {
		$data = array(		 		
			'user_id'          	=> 	$orderID,  		
            'landmark'         => 	$order['landmark'],			
			'address' 	       	=> 	$order['address'],				
			'phone'	      	 	=> 	$order['phone'],
            'alterphone'	   	=> 	$order['alterphone'],				  	
			'status'			=>	0,
			'date_added'		=>	date('Y-m-d H:i:s'), 
			'date_updated'		=>	date('Y-m-d H:i:s'),  	
		);	
		$updateorderid=$this->tableGateway->update($data, array('user_id' => $orderID));
		return $updateorderid;
    }
	public function getuserdetailesData($user_id)
    {
	    $select = $this->tableGateway->getSql()->select();	
		$select->where('user_id= "'.$user_id.'"');
		$resultSet = $this->tableGateway->selectWith($select);	
		return $resultSet;
	}
}